package com.pig4cloud.pig.admin.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.admin.api.entity.BizAgreementSignEntity;
import com.pig4cloud.pig.admin.service.BizAgreementSignService;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.plugin.excel.annotation.RequestExcel;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 协议签约表
 *
 * @author pig
 * @date 2025-03-24 09:19:08
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/bizAgreementSign")
@Tag(description = "bizAgreementSign", name = "协议签约表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class BizAgreementSignController {

	private final BizAgreementSignService bizAgreementSignService;

	/**
	 * 分页查询
	 *
	 * @param page             分页对象
	 * @param bizAgreementSign 协议签约表
	 * @return
	 */
	@Operation(summary = "分页查询", description = "分页查询")
	@GetMapping("/page")
	public R getBizAgreementSignPage(@ParameterObject Page page, @ParameterObject BizAgreementSignEntity bizAgreementSign) {
		LambdaQueryWrapper<BizAgreementSignEntity> wrapper = Wrappers.lambdaQuery();
		return R.ok(bizAgreementSignService.page(page, wrapper));
	}


	/**
	 * 通过条件查询协议签约表
	 *
	 * @param bizAgreementSign 查询条件
	 * @return R  对象列表
	 */
	@Operation(summary = "通过条件查询", description = "通过条件查询对象")
	@GetMapping("/details")
	public R getDetails(@ParameterObject BizAgreementSignEntity bizAgreementSign) {
		return R.ok(bizAgreementSignService.list(Wrappers.query(bizAgreementSign)));
	}

	/**
	 * 新增协议签约表
	 *
	 * @param bizAgreementSign 协议签约表
	 * @return R
	 */
	@Operation(summary = "新增协议签约表", description = "新增协议签约表")
	@SysLog("新增协议签约表")
	@PostMapping
	public R save(@RequestBody BizAgreementSignEntity bizAgreementSign) {
		return R.ok(bizAgreementSignService.save(bizAgreementSign));
	}

	/**
	 * 修改协议签约表
	 *
	 * @param bizAgreementSign 协议签约表
	 * @return R
	 */
	@Operation(summary = "修改协议签约表", description = "修改协议签约表")
	@SysLog("修改协议签约表")
	@PutMapping
	public R updateById(@RequestBody BizAgreementSignEntity bizAgreementSign) {
		return R.ok(bizAgreementSignService.updateById(bizAgreementSign));
	}

	/**
	 * 通过id删除协议签约表
	 *
	 * @param ids id列表
	 * @return R
	 */
	@Operation(summary = "通过id删除协议签约表", description = "通过id删除协议签约表")
	@SysLog("通过id删除协议签约表")
	@DeleteMapping
	public R removeById(@RequestBody Long[] ids) {
		return R.ok(bizAgreementSignService.removeBatchByIds(CollUtil.toList(ids)));
	}


	/**
	 * 导出excel 表格
	 *
	 * @param bizAgreementSign 查询条件
	 * @param ids              导出指定ID
	 * @return excel 文件流
	 */
	@ResponseExcel
	@GetMapping("/export")
	public List<BizAgreementSignEntity> exportExcel(BizAgreementSignEntity bizAgreementSign, Long[] ids) {
		return bizAgreementSignService.list(Wrappers.lambdaQuery(bizAgreementSign).in(ArrayUtil.isNotEmpty(ids), BizAgreementSignEntity::getId, ids));
	}

	/**
	 * 导入excel 表
	 *
	 * @param bizAgreementSignList 对象实体列表
	 * @param bindingResult        错误信息列表
	 * @return ok fail
	 */
	@PostMapping("/import")
	public R importExcel(@RequestExcel List<BizAgreementSignEntity> bizAgreementSignList, BindingResult bindingResult) {
		return R.ok(bizAgreementSignService.saveBatch(bizAgreementSignList));
	}
}
